namespace CSharpPro._1020;

//1020作业二创建学生类Student
public class Student
{
    private int _id;         
    private string _name;   
    private int _age;        
    private string _major;  
    
    public Student(int id, string name, int age, string major)
    {
        Id = id;          
        Name = name;
        Age = age;
        Major = major;
    }
    public int Id
    {
        get => _id;
        set
        {
            if (value <= 0)
                throw new ArgumentException("学号必须是正整数");
            _id = value;
        }
    }
    public string Name
    {
        get => _name;
        set
        {
            if (string.IsNullOrWhiteSpace(value))
                throw new ArgumentException("姓名不能为空");
            _name = value.Trim();
        }
    }
    public int Age
    {
        get => _age;
        set
        {
            if (value < 0 || value > 150)
                throw new ArgumentException("年龄必须在0-150之间");
            _age = value;
        }
    }
    public string Major
    {
        get => _major;
        set
        {
            if (string.IsNullOrWhiteSpace(value))
                throw new ArgumentException("专业不能为空");
            _major = value.Trim();
        }
    }
    public void ShowInfo()
    {
        Console.WriteLine("===== 学生信息 =====");
        Console.WriteLine($"学号：{Id}");
        Console.WriteLine($"姓名：{Name}");
        Console.WriteLine($"年龄：{Age}");
        Console.WriteLine($"专业：{Major}");
        Console.WriteLine(); // 空行分隔
    }
    public void UpdateAge(int newAge)
    {
        Age = newAge;
        Console.WriteLine($"年龄已更新为：{Age}");
    }
}